var index_vue_method = {
  check_error_message (that, message) {
    that.$notify.error({
      title: '校验错误',
      message: message
    });
  },
  read_plugin_save (that) {
    return_label: {
      error_message = ""
      switch (that.read_plugin_name) {
        case "mysqlreader":
          that.mysql_reader.name = that.read_plugin_name
          that.json_result_obj.job.content[0].reader.parameter = {
            "username": that.mysql_reader.username,
            "password": that.mysql_reader.password,
            "column": [
              that.mysql_reader.column
            ],
            "connection": [
              {
                "table": [
                  that.mysql_reader.table
                ],
                "jdbcUrl": [
                  that.mysql_reader.jdbcUrl
                ],
                "driver": that.mysql_reader.driver
              }
            ],
            "splitPk": that.mysql_reader.splitPk,
            "autoPk": that.mysql_reader.autoPk,
            "where": that.mysql_reader.where,
            "querySql": that.mysql_reader.querySql
          }
          that.mysql_reader.jdbcUrl == "" ? error_message = 'JDBC连接信息配置错误' : {}
          that.mysql_reader.username == "" ? error_message = '数据库账号信息配置错误' : {}
          that.mysql_reader.password == "" ? error_message = '数据库密码信息配置错误' : {}
          that.mysql_reader.table == "" ? error_message = '数据库表信息配置错误' : {}
          that.mysql_reader.column == "" ? error_message = '数据库列信息配置错误' : {}
          if (error_message !== "") {
            that.check_error_message(error_message)
            error_message = ""
            break return_label
          }

          break;
        case "postgresqlreader":
          break;
        default:
          break;
      }
      if (that.step_num++ > 2) that.step_num = 1;
      that.json_result_obj.job.content[0].reader.name = that.read_plugin_name
      that.read_plugin_name = ''
    }



  },
  write_plugin_save (that) {
    return_label: {
      error_message = ""
      switch (that.write_plugin_name) {
        case "mysqlwriter":
          that.mysql_writer.name = that.write_plugin_name
          that.json_result_obj.job.content[0].writer.parameter = {
            "username": that.mysql_writer.username,
            "password": that.mysql_writer.password,
            "writeMode": that.mysql_writer.writeMode,
            "batchSize": that.mysql_writer.batchSize,
            "session": that.mysql_writer.session,
            "column": [
              that.mysql_writer.column
            ],
            "preSql": [
              that.mysql_writer.preSql
            ],
            "postSql": [
              that.mysql_writer.postSql
            ],
            "connection": [
              {
                "jdbcUrl": that.mysql_writer.jdbcUrl,
                "table": [
                  that.mysql_writer.table
                ]
              }
            ]
          }

          that.mysql_writer.jdbcUrl == "" ? error_message = 'JDBC连接信息配置错误' : {}
          that.mysql_writer.username == "" ? error_message = '数据库账号信息配置错误' : {}
          that.mysql_writer.password == "" ? error_message = '数据库密码信息配置错误' : {}
          that.mysql_writer.table == "" ? error_message = '数据库表信息配置错误' : {}
          that.mysql_writer.column == "" ? error_message = '数据库列信息配置错误' : {}
          if (error_message !== "") {
            that.check_error_message(error_message)
            error_message = ""
            break return_label
          }
          break;
        case "postgresqlwriter":
          that.postgresql_writer.name = that.write_plugin_name

          that.json_result_obj.job.content[0].writer.parameter = {
            "username": that.postgresql_writer.username,
            "password": that.postgresql_writer.password,
            "writeMode": that.postgresql_writer.writeMode,
            "batchSize": that.postgresql_writer.batchSize,
            "column": [
              that.postgresql_writer.column
            ],
            "preSql": [
              that.postgresql_writer.preSql
            ],
            "postSql": [
              that.postgresql_writer.postSql
            ],
            "connection": [
              {
                "jdbcUrl": that.postgresql_writer.jdbcUrl,
                "table": [
                  that.postgresql_writer.table
                ]
              }
            ]
          }

          that.postgresql_writer.jdbcUrl == "" ? error_message = 'JDBC连接信息配置错误' : {}
          that.postgresql_writer.username == "" ? error_message = '数据库账号信息配置错误' : {}
          that.postgresql_writer.password == "" ? error_message = '数据库密码信息配置错误' : {}
          that.postgresql_writer.table == "" ? error_message = '数据库表信息配置错误' : {}
          that.postgresql_writer.column == "" ? error_message = '数据库列信息配置错误' : {}
          if (error_message !== "") {
            that.check_error_message(error_message)
            error_message = ""
            break return_label
          }
          break;
        case "streamwriter":
          that.stream_writer.name = that.write_plugin_name
          that.json_result_obj.job.content[0].writer.parameter = {
            "encoding": that.stream_writer.encoding,
            "print": that.stream_writer.print
          }
          that.stream_writer.encoding == "" ? error_message = '字符集信息配置错误' : {}
          if (error_message !== "") {
            that.check_error_message(error_message)
            error_message = ""
            break return_label
          }




          break;
        case "greenplumwriter":
          that.greenplum_writer.name = that.write_plugin_name
          that.json_result_obj.job.content[0].writer.parameter = {
            "username": that.greenplum_writer.username,
            "password": that.greenplum_writer.password,
            "queueSize": that.greenplum_writer.queueSize,
            "numProc": that.greenplum_writer.numProc,
            "numWriter": that.greenplum_writer.numWriter,
            "column": [
              that.greenplum_writer.column
            ],
            "preSql": [
              that.greenplum_writer.preSql
            ],
            "postSql": [
              that.greenplum_writer.postSql
            ],
            "connection": [
              {
                "jdbcUrl": that.greenplum_writer.jdbcUrl,
                "table": [
                  that.greenplum_writer.table
                ]
              }
            ]
          }

          that.greenplum_writer.jdbcUrl == "" ? error_message = 'JDBC连接信息配置错误' : {}
          that.greenplum_writer.username == "" ? error_message = '数据库账号信息配置错误' : {}
          that.greenplum_writer.password == "" ? error_message = '数据库密码信息配置错误' : {}
          that.greenplum_writer.table == "" ? error_message = '数据库表信息配置错误' : {}
          that.greenplum_writer.column == "" ? error_message = '数据库列信息配置错误' : {}
          if (error_message !== "") {
            that.check_error_message(error_message)
            error_message = ""
            break return_label
          }
          break;
        case "streamwriter":
          that.stream_writer.name = that.write_plugin_name
          that.json_result_obj.job.content[0].writer.parameter = {
            "encoding": that.stream_writer.encoding,
            "print": that.stream_writer.print
          }
          that.stream_writer.encoding == "" ? error_message = '字符集信息配置错误' : {}
          if (error_message !== "") {
            that.check_error_message(error_message)
            error_message = ""
            break return_label
          }
          break;
        case "oraclewriter":
          that.oracle_writer.name = that.write_plugin_name
          that.json_result_obj.job.content[0].writer.parameter = {
            "username": that.oracle_writer.username,
            "password": that.oracle_writer.password,
            "writeMode": that.oracle_writer.writeMode,
            "batchSize": that.oracle_writer.batchSize,
            "session": that.oracle_writer.session,
            "column": [
              that.oracle_writer.column
            ],
            "preSql": [
              that.oracle_writer.preSql
            ],
            "postSql": [
              that.oracle_writer.postSql
            ],
            "connection": [
              {
                "jdbcUrl": that.oracle_writer.jdbcUrl,
                "table": [
                  that.oracle_writer.table
                ]
              }
            ]
          }

          that.oracle_writer.jdbcUrl == "" ? error_message = 'JDBC连接信息配置错误' : {}
          that.oracle_writer.username == "" ? error_message = '数据库账号信息配置错误' : {}
          that.oracle_writer.password == "" ? error_message = '数据库密码信息配置错误' : {}
          that.oracle_writer.table == "" ? error_message = '数据库表信息配置错误' : {}
          that.oracle_writer.column == "" ? error_message = '数据库列信息配置错误' : {}
          if (error_message !== "") {
            that.check_error_message(error_message)
            error_message = ""
            break return_label
          }
          break;
        default:
          break;
      }
      if (that.step_num++ > 2) that.step_num = 1;
      that.json_result_obj.job.content[0].writer.name = that.write_plugin_name
      that.write_plugin_name = ''
      //为下一步生成一个随机名字
      that.genJobName()
    }
  },
  exec_plugin (that) {
    if (that.job_name == "") {
      that.check_error_message("任务名称配置错误")
      return
    }

    axios
      .post("/job", { "Json": JSON.stringify(that.json_result_obj, null, 2), "Name": that.job_name, "Exp": that.job_exp })
      .then(response => {
        that.$notify.info({
          "title": "调用成功",
          "message": response.data
        })
        that.refresh_job_info()
      })
      .catch(function (error) { // 请求失败处理
        that.$notify.error({
          "title": "调用失败",
          "message": error
        })
        console.log(error);
      });




    //结果json变量重新初始化

    that.json_result_obj = {
      "job": {
        "setting": {
          "speed": {
            "channel": 3,
            "bytes": -1
          }
        },
        "content": [
          {
            "reader": {
              "name": "",
              "parameter": {
              }
            },
            "writer": {
              "name": "",
              "parameter": {
              }
            }
          }
        ]
      }
    }

    that.job_name = ""
    //继续下一步
    if (that.step_num++ > 2) that.step_num = 1;
  },
  read_plugin_value_change (that, selVaule) {
    that.read_plugin_name = selVaule
    if (that.read_plugin_name !== "") {
      //to do
    }

  },
  write_plugin_value_change (that, selValue) {
    that.write_plugin_name = selValue
    if (that.write_plugin_name !== "") {
      //to do
    }
  },
  //通道个数改变
  channel_value_change (that, selValue) {
    that.json_result_obj.job.setting.speed.channel = selValue
  },
  //刷新任务表格函数
  refresh_job_info (that) {
    axios
      .get("/info")
      .then(response => {
        if (response.status == 200) {
          that.jobInfoData = response.data.data
        } else {
          console.log(response)
        }

      })
      .catch(function (error) { // 请求失败处理
        that.$notify.error({
          "title": "调用失败",
          "message": error
        })
        console.log(error);
      });
  },
  //任务删除函数
  jobInfoDeleteRow (that, row) {
    axios
      .delete("/info", { data: row })
      .then(response => {
        if (response.status == 200) {
          console.log(response.data.message)
          that.refresh_job_info()
        } else {
          console.log(response)
        }

      })
      .catch(function (error) { // 请求失败处理
        that.$notify.error({
          "title": "调用失败",
          "message": error
        })
        console.log(error);
      });

  },
  //任务开始处理函数
  jobInfoStartRow (that, row) {
    axios
      .put("/info", row)
      .then(response => {
        if (response.status == 200) {
          that.$notify.info({
            "title": "调用成功",
            "message": response.data.message
          })
          console.log(response.data.message)
        } else {
          console.log(response)
        }

      })
      .catch(function (error) { // 请求失败处理
        that.$notify.error({
          "title": "调用失败",
          "message": error
        })
        console.log(error);
      });

  },
  //任务编辑处理函数
  jobInfoEditRow (that, row) {
    that.$notify.info({
      "title": "说明",
      "message": "没有实现功能"
    })
  },
  //查看日志处理函数
  jobInfoLogInfo (that, row) {
    that.file_log_data = ""
    that.file_log_diag_visual = true
    if ((JSON.stringify(that.websocket) == "{}")) {
      that.initWebSocket(row)
    } else {
      //前端close不好使
      that.websocket.close()
    }
  },
  //关闭查看日志窗口
  jobInfoLogDiagClose (that) {
    that.file_log_data = ""
    that.file_log_diag_visual = false
    if ((JSON.stringify(that.websocket) !== "{}")) {
      //前端close不好使
      that.websocket.close()
    }
  },
  genJobName (that) {
    var t = "ABCDEFGHJKMNPQRSTWXYZ"
    n = ""
    for (i = 0; i < 5; i++) n += t.charAt(Math.floor(Math.random() * t.length));
    that.job_name = n
  },
  initWebSocket (that, row) {
    ip_and_port = window.location.host
    that.websocket = new WebSocket('ws://' + ip_and_port + '/ws?filename=' + row.Uuid + "_" + row.Name + ".json.log")
    that.websocket.onopen = () => {
      console.log('ws连接状态：' + that.websocket.readyState);
      //that.websocket.send(row.Uuid + "_" + row.Name + ".log");
    }
    that.websocket.onmessage = (data) => {
      //console.log('接收到来自服务器的消息');
      that.file_log_data = that.file_log_data.concat(data.data.concat("\r\n"))
      //延时滚动 滚动条
      that.$nextTick(() => {
        setTimeout(() => {
          const textarea = document.getElementById('log_scroll_text');
          textarea.scrollTop = textarea.scrollHeight;
        }, 500)
      })
    }
    that.websocket.onclose = () => {
      console.log('ws连接状态：' + that.websocket.readyState);
    }
    that.websocket.onerror = function (error) {
      that.$notify.error({
        "title": "websocker error",
        "message": "websocket 连接失败"
      })
      console.log(error);
    }

  }
}